package com.elasticsearch.repository;

import com.elasticsearch.common.Constants;
import com.elasticsearch.dto.FaqDTO;
import org.elasticsearch.search.SearchHits;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.HighlightParameters;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 关键字搜索存储库
 *
 * @author Amadeus
 * @date 2023/06/27
 */
@Repository
public interface KeywordSearchRepository extends ElasticsearchRepository<FaqDTO, String> {

    /**
     * 发现通过标题和内容
     *
     * @param title   标题
     * @param content 内容
     * @return {@link List<FaqDTO>}
     */
    @Highlight(
            fields = {@HighlightField(name = "title"), @HighlightField(name = "content")},
            parameters = @HighlightParameters(preTags = {Constants.HIGHLINE_PRETAGS}, postTags = {Constants.HIGHLINE_POSTTAGS}, numberOfFragments = 0)
    )
    List<FaqDTO> findByTitleOrContent(String title, String content);

}
